<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #clockBox {
            height: 100px;
            line-height: 100px;
            font-size: 28px;
            text-align: center;
            background: -webkit-linear-gradient(left top, yellow, yellowGreen)
        }
    </style>
</head>

<body>
    <div id="clockBox"></div>
</body>

</html>
<script>
    //---获取操作的dom元素 
    var clockBox = document.getElementById("clockBox");
    //---时间内容
    function getTime() {
        var time = new Date();
        var year = time.getFullYear();//年
        var month = time.getMonth() + 1;// 0-11  对应1-12 月
        var date = time.getDate();
        var day = time.getDay();//0-6 对应的是星期日到星期六
        var weekAry = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        var hour = time.getHours();
        var minutes = time.getMinutes();
        var seconds = time.getSeconds();
        return year + "年" + addZero(month )+ "月" + addZero(date) + "日" + " " + weekAry[day] + " " + addZero(hour) + "时" + addZero(minutes) + "分" + addZero(seconds) + "秒";
    }
     
    function addZero(n){
        return n<10?"0"+n:n;
    } 
    clockBox.innerText = getTime();
    setInterval(()=>{
        clockBox.innerText = getTime();
    },1000)


</script>